<?php 
	class Zuoyes extends CI_Model{

		function __construct(){
			parent::__construct();
		}

		function get_child_zuoyes($limit = 0, $offset = 10, $conditions = array()){
			$where = " 1=1 ";
			if(!empty($conditions['child_id'])){
				$where .= " AND z.childer_id='{$conditions['child_id']}' ";
			}
			if(!empty($conditions['time_type'])){
				$today_time = strtotime(date('Y-m-d', time()));
				//今天的作业
				if($conditions['time_type'] == 1){
					$where .= " AND z.add_time >= $today_time ";
				}elseif($conditions['time_type'] == 2){	//往期作业
					$where .= " AND z.add_time < $today_time ";
				}
			}
			$sql = "SELECT SQL_CALC_FOUND_ROWS z.*,s.name, s.img FROM {$this->db->dbprefix}zuoye AS z  ";
			$sql .= " LEFT JOIN {$this->db->dbprefix}b_subject AS s ON(s.id=z.subject_id) ";
			$sql .= "WHERE $where ORDER BY z.id DESC";
			if(!empty($limit) || !empty($offset)){
				$sql .= " LIMIT $limit, $offset";
			}
			$result = $this->db->query($sql)->result_array();
			$row_num =  $this->db->query('SELECT FOUND_ROWS() as row_num;')->row_array();
			return array("count" => $row_num['row_num'], "list" => $result);
		}

		function get_child_zuoye_rewards($limit = 0, $offset = 10, $conditions = array()){
			$where = " 1=1 ";
			if(!empty($conditions['child_id'])){
				$where .= " AND child_id='{$conditions['child_id']}' ";
			}
			
			$sql = "SELECT SQL_CALC_FOUND_ROWS * FROM {$this->db->dbprefix}zuoye_rewards WHERE $where ORDER BY id DESC ";
			if(!empty($limit) || !empty($offset)){
				$sql .= " LIMIT $limit, $offset";
			}
			$result = $this->db->query($sql)->result_array();
			$row_num =  $this->db->query('SELECT FOUND_ROWS() as row_num;')->row_array();
			return array("count" => $row_num['row_num'], "list" => $result);
		}
	}